package com.rftennis.web.servlets;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.common.OrderUtil;
import com.rftennis.ao.OrderAo;
import com.rftennis.ao.OrderItemAo;
import com.rftennis.dto.JSONResponce;
import com.rftennis.service.impl.OrderItemServiceImpl;
import com.rftennis.service.impl.OrderServiceImpl;
@Controller
public class AddOrderServlet {
	@Autowired
	OrderServiceImpl o;
	@Autowired
	OrderItemServiceImpl t;
	@PostMapping("/order/add.do")
	public @ResponseBody JSONResponce add(OrderAo ao,OrderItemAo[] to) throws Exception {
		String uuid=OrderUtil.uuid();
		ao.setId(uuid);
		o.addOrder(ao);
		for(int i=0;i<to.length;i++) {
			to[i].setOrderId(uuid);
			t.addOrderItem(to[i]);
		}
		return JSONResponce.ok();
	}
}
